package com.yanqu.road.server.cmd.crossunion;

import com.yanqu.road.entity.union.UnionBaseInfo;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.logic.pb.UnionBasePb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.crossunion.activity.CrossUnionActivityRankDataProto;
import com.yanqu.road.pb.player.PlayerProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.union.CrossUnionActivityDataMgr;
import com.yanqu.road.server.manager.user.CrossUserMgr;
import com.yanqu.road.server.protocol.CrossProtocol;

import java.math.BigInteger;
import java.util.List;

@Cmd(code = CrossProtocol.C_CROSS_UNION_ACTIVITY_GROUP_USER_VALUE_CHANGE, desc = "玩家商会值变动,商会跨服分组用")
public class CrossUnionActivityGroupUserValueChangeCmd extends CrossUnionCommand {
    private long userId;
    private int activityId;
    private int conditionType;
    private BigInteger value;
    private String unionId;
    private int changeType;
    private List<CrossUnionActivityRankDataProto.CrossUnionMemberPosDataMsg> memberList;
    private long unionServerId;
    private UnionBaseInfo unionBaseInfo;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        CrossUnionActivityRankDataProto.CrossUnionActivityUserDataMsg msg = CrossUnionActivityRankDataProto.CrossUnionActivityUserDataMsg.parseFrom(packet.getBytes());
        activityId = msg.getActivityId();
        conditionType = msg.getConditionType();
        userId = msg.getUserId();
        value = new BigInteger(msg.getValue());
        unionId = msg.getUnionId();
        changeType = msg.getChangeType();
        PlayerProto.PlayerBaseTempMsg userBaseInfo = msg.getUserBaseInfo();
        if (userId > 0) {
            CrossUserMgr.updateUserBaseInfoChange(userId, PlayerBasePb.parseBaseUserInfo(userBaseInfo));
        }
        memberList = msg.getMemberList();
        unionServerId = msg.getUnionServerId();
        if (msg.hasUnionBaseInfo()) {
            unionBaseInfo = UnionBasePb.parseUnionBaseInfo(msg.getUnionBaseInfo());
        }
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        CrossUnionActivityDataMgr.changeUserData(activityId, conditionType, userId, value, unionId,changeType,memberList,unionServerId,unionBaseInfo);
    }

    @Override
    public void sendData() {

    }
}
